package com.feng.config;

import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import com.feng.utils.Const;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.chat.prompt.ChatOptions;
//import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringAiConfig {

    @Bean
    public ChatMemory chatMemory(){
        return new InMemoryChatMemory();
    }

    @Bean
    @Qualifier("chatClient")
    public ChatClient chatClient(DashScopeChatModel model, ChatMemory memory){
        return ChatClient.builder(model)
                .defaultSystem(Const.SYSTEM_AIChat_PROMPT) //服务端设置的默认提示词
                .defaultAdvisors(new SimpleLoggerAdvisor(),//配置日志
                        new MessageChatMemoryAdvisor(memory)) //配置聊天记录
                .build();
    }
    @Bean
    @Qualifier("gameClient")
    public ChatClient gameClient(DashScopeChatModel model, ChatMemory memory){
        return ChatClient.builder(model)
                .defaultSystem(Const.SYSTEM_GAME_PROMPT) //服务端设置的默认提示词
                .defaultAdvisors(new SimpleLoggerAdvisor(),//配置日志
                        new MessageChatMemoryAdvisor(memory)) //配置聊天记录
                .build();
    }

}
